{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 量子近似优化算法\n",
    "\n",
    "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/case_library/mindspore_quantum_approximate_optimization_algorithm.ipynb)&emsp;\n",
    "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/mindquantum/zh_cn/case_library/mindspore_quantum_approximate_optimization_algorithm.py)&emsp;\n",
    "[![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindquantum/docs/source_zh_cn/case_library/quantum_approximate_optimization_algorithm.ipynb)\n",
    "\n",
    "## 概述\n",
    "\n",
    "量子近似优化算法（Quantum Approximate Optimization Algorithm，QAOA）是利用量子计算机来近似解决组合优化问题的量子算法，最早由Farhi等人于2014年提出。在本文档里，我们将利用QAOA算法来解决最大割问题（Max-Cut），来熟悉MindSpore Quantum中量子线路的搭建和训练。\n",
    "\n",
    "## 环境准备\n",
    "\n",
    "本文档所需要的额外库：\n",
    "\n",
    "- networkx\n",
    "\n",
    "> `networkx`是创建、操作和研究复杂网络的结构、动态和功能库。可通过如下代码来进行安装。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```bash\n",
    "pip3 install networkx\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 安装 mindquantum, networkx\n",
    "!pip install mindquantum -i https://pypi.mirrors.ustc.edu.cn/simple\n",
    "!pip install networkx -i https://pypi.mirrors.ustc.edu.cn/simple"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Max-Cut问题描述\n",
    "\n",
    "Max-Cut问题是图论中的一个NP-complete问题，它需要将一个图中的顶点分成两部分，并使得两部分被切割的边最多。如下图（a），一个图由五个顶点构成，相互连接的边为```(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (0, 4)```。为了使得被切割的边最多，我们尝试通过（b）图的分割，将1、2、4分为一组，0、3分成另一组，因此可得到被切割的边有5条。后面我们将用穷举法验证这个解是否正确。当图中顶点较少时，我们可以在较短时间内通过穷举法找到最大的切割边数，但当图中顶点增多时，我们很难找到有效的经典算法来解决Max-Cut问题，因为这类NP-complete问题很有可能不存在多项式时间算法。但尽管精确解不容易得到，我们却可以想办法在多项式时间内找到问题的一个近似解，这就是近似优化算法。下面，我们介绍怎么将Max-Cut问题转化为一个哈密顿量的基态能量求解问题。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![max cut](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindquantum/docs/source_zh_cn/images/Max_Cut.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Max-Cut问题量子化\n",
    "\n",
    "这里我们将图中的每个顶点赋予一个量子比特，当顶点被分到左边时，我们将该顶点上的量子比特设置为$\\left|0\\right>$态，同理，右边为$\\left|1\\right>$态，当两个顶点被分到不同的集合中时，这两个顶点上的比特将处于不同的量子态。例如对于第0个顶点和第1个顶点，当其连线被切割时，两个顶点上的比特对应的量子态可以表示为$|01\\rangle$（顶点1：左，顶点0：右）或$|10\\rangle$（顶点1：右，顶点0：左）；若它们被分到同一边，则对应量子态为$|00\\rangle$或$|11\\rangle$。因此我们只要找到一个哈密顿量$H$使得：当有连线的两个顶点处于不同量子态时，哈密顿量的期望值为-1，即\n",
    "\n",
    "$$\n",
    "\\langle 01|H|01\\rangle=-1,\\quad \\langle 10|H|10\\rangle=-1\n",
    "$$\n",
    "\n",
    "而当有连线的顶点处于相同量子态时，哈密顿量的期望值为0，即\n",
    "\n",
    "$$\n",
    "\\langle 00|H|00\\rangle=0,\\quad \\langle 11|H|11\\rangle=0\n",
    "$$\n",
    "\n",
    "随后只要使哈密顿量的期望值最小化，就可以找到最大切割边数，以及此时对应的分组情况。之所以将不同量子态时的期望值设为-1，是因为在量子神经网络的训练中，Ansatz中的参数的梯度会一直下降，同时测量值也会一直减少，该训练方法就是以找到最小值为目标，这里我们用它来寻找哈密顿量的基态能量。此时，我们选择哈密顿量$H=(Z_1Z_0-1)/2$，这里$Z$为泡利$Z$算符。此时有：\n",
    "\n",
    "$$\n",
    "Z_1Z_0|00\\rangle=|00\\rangle,\\quad Z_1Z_0|11\\rangle=|11\\rangle, \\quad Z_1Z_0|01\\rangle=-|01\\rangle, \\quad Z_1Z_0|10\\rangle=-|10\\rangle\n",
    "$$\n",
    "\n",
    "因此当顶点被分到不同集合时：\n",
    "\n",
    "$$\n",
    "\\left<01\\right|H\\left|01\\right>=\\frac{1}{2}\\left<01\\right|Z_1Z_0\\left|01\\right>-\\frac{1}{2}=-1\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\left<10\\right|H\\left|10\\right>=\\frac{1}{2}\\left<10\\right|Z_1Z_0\\left|10\\right>-\\frac{1}{2}=-1\n",
    "$$\n",
    "\n",
    "而当顶点被分到同一集合中时，不难验证此时：\n",
    "\n",
    "$$\n",
    "\\left<00\\right|H\\left|00\\right>=\\frac{1}{2}\\left<00\\right|Z_1Z_0\\left|00\\right>-\\frac{1}{2}=0\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\left<11\\right|H\\left|11\\right>=\\frac{1}{2}\\left<11\\right|Z_1Z_0\\left|11\\right>-\\frac{1}{2}=0\n",
    "$$\n",
    "\n",
    "因此，我们只要对图中的每条边写出上述哈密顿量，然后将所有边求和，即可写出图对应的哈密顿量$H$，利用量子计算机求得$H$的基态能量与基态，我们就可以得到该图的Max-Cut切割方案与最大切割边数。我们记所有边的集合为$C$，所有边条数为$c$，则哈密顿量可写为：\n",
    "\n",
    "$$\n",
    "H=\\sum_{(i,j)\\in C}(Z_iZ_j-1)/2\n",
    "$$\n",
    "\n",
    "## 导入相关依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mindquantum.core.circuit import Circuit, UN\n",
    "from mindquantum.core.gates import H, Rzz, RX\n",
    "from mindquantum.core.operators import Hamiltonian, QubitOperator\n",
    "from mindquantum.framework import MQAnsatzOnlyLayer\n",
    "from mindquantum.simulator import Simulator\n",
    "import networkx as nx\n",
    "import mindspore.nn as nn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搭建所需求解的图\n",
    "\n",
    "通过`add_path`可在图中添加边。最后画出图的结构。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApQAAAHzCAYAAACe1o1DAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAABSCklEQVR4nO3dd3iUBdr24WsmBQglkFAUQoKQABoCiUsUYbJ+KNIFbIAIKNYVsb2LvWB3dd1VkbLrouwyNEUElSKIogaCgC5IQFoQCDVAgiGNlJn5/mCTJZtCkpnJM+V3HofHi87kmSv7Srh8yn2bHA6HQwAAAEAdmY0OAAAAAO9GoQQAAIBTKJQAAABwCoUSAAAATqFQAgAAwCkUSgAAADiFQgkAAACnUCgBAADgFAolAAAAnEKhBAAAgFMolAAAAHAKhRIAAABOoVACAADAKRRKAAAAOIVCCQAAAKdQKAEAAOAUCiUAAACcQqEEAACAUyiUAAAAcAqFEgAAAE6hUAIAAMApFEoAAAA4hUIJAAAAp1AoAQAA4BQKJQAAAJxCoQQAAIBTKJQAAABwCoUSAAAATqFQAgAAwCkUSgAAADiFQgkAAACnUCgBAADgFAolAAAAnEKhBAAA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IXpxWKxLj/naTfF69pH79frrr+uqq67Szp07XXp8wB9QKAEAXmV0YqQm9+/skmM91r+LxlzZQc8995w2bNigvLw8XX755Zo6darsdoacAzXFQzkAAK+0cHO6pny+QyV2h2z2mv9RFmA2KdBs0kvDYjUqsfzWnIKCAj355JOaOnWqrr32Ws2ePVvt21c9agjAORRKAIDXOpSVr/9b+KM2H8qRSQ45qhl/HmA2yWZ3KCm6pV67IU7tw0KqfO+aNWs0YcIE5eTkaMaMGbr11ltlMrl7tDrgvbjkDQDwWu3DQnRF3kad/NfDGv27tooKD6lQKU2SosJDNO7KKK159Pey3nVltWVSkvr166dt27ZpyJAhuu222zR69GhlZWW57fsAvB1nKAEAXq179+669NJL9dFHH0mS8gpLdCAzT0UldgUHmtUhvLFTG3A++ugj3X///WrYsKE+/PBDDRw40FXRAZ/BGUoAgNf6+eeflZqaqnHjxpX9s8YNAhXbNlQJkS0U2zbU6XWKo0aNUmpqqrp3765BgwZp4sSJysvLczY64FMolAAAr2W1WtWqVSsNGDDArZ/Trl07rVy5UtOnT9c///lPJSQkaOPGjW79TMCbUCgBAF7JZrNp/vz5Gj16tIKCgtz+eSaTSRMnTtTWrVvVokUL9enTh2HowH9QKAEAXunrr7/WsWPHyl3urg+dO3fW+vXr9fzzz+u1115jGDogCiUAwEtZrVZ16dJFPXv2rPfPDgwM1PPPP68ffviBYeiAKJQAAC+Um5urTz/9VOPGjTN0PmTPnj3173//W/fee68efvhh9e/fX4cPHzYsD2AUCiUAwOssWbJE+fn5uu2224yOokaNGundd9/V6tWrtWvXLsXFxWn+/PliKh/8CXMoAQBep3///iosLNR3331ndJRyTp8+rUmTJmn+/PkaOXKkZs6cqbCwMKNjAW7HGUoAgFc5evSovv7663p/GKcmWrRooXnz5mnhwoX66quv1K1bN61atcroWIDbUSgBAF5l/vz5CgoK0s0332x0lCqVDkOPi4vTwIED9cADDzAMHT6NS94AAK/SvXt3de3aVR9//LHRUS7I4XBo5syZmjx5siIiImS1WnXllVcaHQtwO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KJWCgsLdcMNN+jEiRNasWIFZRJuY7FY9OOPP6qgoKDeP5tViwBQOxRK1JjdbteECRP0ww8/6PPPP1fnzp2NjgQflpSUpOLiYm3evLneP5tViwBQOxRK1Nizzz6rBQsWyGq18tQr3K5bt25q1qyZIfdRsmoRAGqHOZSokffff1+vv/66/vznP+uWW24xOg78QEBAgHr37l3vhbJ01eKiRYvq9XMBwJtxhhIXtHLlSk2cOFETJ07UH//4R6PjwI9YLBatX79eNput3j6TVYsAUHsUSlRry5YtGjlypAYPHqx3331XJpPJ6EjwI0lJSTpz5oy2b99eL5/HqkUAqBsKJaqUnp6uIUOGqGvXrlqwYIECA7lDAvUrMTFRQUFB9XbZm1WLAFA3FEpUKjs7W0OGDFFwcLC++OILNW7c2OhI8EONGjVSz549661QsmoRAOqGQokKioqKdNNNN+nw4cNauXKlLrroIqMjwY9ZLBYlJyfL3TsYWLUIAHXHT02U43A4dO+99yo5OVlLly7VpZdeanQk+DmLxaIjR47o4MGDbv0cVi0CQN1RKFHOiy++qH/961+aPXu2rr76aqPjAGWXn9192dtqteqKK65gYD8A1AGFEmX++c9/6sUXX9Srr76qMWPGGB0HkCSFh4frsssuc2uhPHnypFauXMnZSQCoIwolJElr1qzRPffco7vvvltPPfWU0XGAciwWi1sL5UcffSRJGj16tNs+AwB8GYUSSk1N1U033aR+/fppxowZzJqEx7FYLNqxY4cyMzPdcnyr1apBgwaxahEA6ohC6eeOHDmiwYMHq2PHjvr4448VFBRkdCSgAovFIklKSUlx+bF3796tTZs2afz48S4/NgD4CwqlH8vJydGQIUMkScuXL1fTpk0NTgRUrkOHDmrXrp1bLnuzahEAnMfqEz9VXFyskSNHav/+/Vq3bp3atm1rdCSgSiaTyS33UbJqEQBcgzOUfsjhcGjixIlas2aNFi9erLi4OKMjARdksVi0efNmFRQUuOyYrFoEANegUPqh119/XbNmzdKsWbPUr18/o+MANWKxWFRcXKzNmze77JisWgQA16BQ+pn58+frmWee0ZQpU3T77bcbHQeosbi4ODVr1sx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",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "graph = nx.Graph()\n",
    "nx.add_path(graph, [0, 1])\n",
    "nx.add_path(graph, [1, 2])\n",
    "nx.add_path(graph, [2, 3])\n",
    "nx.add_path(graph, [3, 4])\n",
    "nx.add_path(graph, [0, 4])\n",
    "nx.add_path(graph, [0, 2])\n",
    "nx.draw(graph, with_labels=True, font_weight='bold')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如上图，我们得到一个由5个节点和6条边构成的图结构。\n",
    "\n",
    "接下来我们用穷举法来看看所有情况的切割边数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "one size: [0] cut= 3\n",
      "one size: [1] cut= 2\n",
      "one size: [1, 0] cut= 3\n",
      "one size: [2] cut= 3\n",
      "one size: [2, 0] cut= 4\n",
      "one size: [2, 1] cut= 3\n",
      "one size: [3] cut= 2\n",
      "one size: [3, 0] cut= 5\n",
      "one size: [3, 1] cut= 4\n",
      "one size: [3, 2] cut= 3\n",
      "one size: [4] cut= 2\n",
      "one size: [4, 0] cut= 3\n",
      "one size: [4, 1] cut= 4\n",
      "one size: [4, 2] cut= 5\n",
      "one size: [4, 3] cut= 2\n"
     ]
    }
   ],
   "source": [
    "for i in graph.nodes:\n",
    "    print('one size:', [i], 'cut=', nx.cut_size(graph, [i]))            # 一组1个节点、另一组4个节点的所有情况\n",
    "    for j in range(i):\n",
    "        print('one size:', [i, j], 'cut=', nx.cut_size(graph, [i, j]))  # 一组2个节点、另一组3个节点的所有情况"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从以上结果可以看出，穷举法得到的最大切割边数为5，如果对节点分组的左右进行区分，则一共有4种分组方法可以使切割边数最大，即该问题有4个简并解。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## QAOA算法整体流程\n",
    "\n",
    "1. 搭建QAOA量子线路，其中ansatz线路包含可以训练的参数\n",
    "2. 初始化线路中的参数\n",
    "3. 运行该量子线路，得到量子态$|\\psi\\rangle$\n",
    "4. 计算目标哈密顿量$H_C$的期望值$\\langle\\psi|H_C|\\psi\\rangle$\n",
    "5. 根据第4步的结果，使用Adam优化器优化线路中参数\n",
    "6. 重复3-5步，直到第4步结果基本不再变化\n",
    "7. 根据第4步的结果，算出目标问题的近似解\n",
    "\n",
    "在该流程中，第2-6步都可以由MindSpore和MindSpore Quantum中现成的包和函数来实现，因此我们将重点关注第1步——量子线路的搭建。\n",
    "\n",
    "![Flowchart](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindquantum/docs/source_zh_cn/images/QAOA_Flowchart.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搭建QAOA量子线路\n",
    "\n",
    "先前提到，我们需要将问题对应的哈密顿量\n",
    "\n",
    "$$\n",
    "H_C=\\sum_{(i,j)\\in C}(Z_iZ_j-1)/2\n",
    "$$\n",
    "\n",
    "最小化来找到问题的解，也就是说我们要找到该哈密顿量的基态。对此我们可以采用量子绝热演化的方法，使系统先处于某一简单哈密顿量$H_B$的基态上，然后使简单的哈密顿量$H_B$绝热地、缓慢地演化至某一复杂的哈密顿量$H_C$，根据绝热定理，系统将始终保持在哈密顿量的基态上，最终达到复杂哈密顿量$H_C$的基态。\n",
    "\n",
    "我们将要搭建的量子线路就是采用以上思路，选取初始简单哈密顿量为\n",
    "\n",
    "$$\n",
    "H_B=\\sum_i -X_i\n",
    "$$\n",
    "\n",
    "并将量子线路制备到$H_B$的基态$|s\\rangle=|+\\rangle^{\\otimes n}$，这里通过对所有量子比特作用[Hadamard门](https://www.mindspore.cn/mindquantum/docs/zh-CN/master/core/gates/mindquantum.core.gates.HGate.html)即可实现。然后连接ansatz含参线路，通过不断地优化其中参数可以使得ansatz线路越来越接近真实绝热演化的效果，最终得到的量子线路可以视为模拟近似了一个真实的绝热演化过程。\n",
    "\n",
    "### ansatz线路\n",
    "\n",
    "在量子绝热演化中，首先选取初始哈密顿量\n",
    "\n",
    "$$\n",
    "H_B=\\sum_i -X_i\n",
    "$$\n",
    "\n",
    "并使系统处于$H_B$的基态$|s\\rangle=|+\\rangle^{\\otimes n}$。然后缓慢地作用如下含时哈密顿量\n",
    "\n",
    "$$\n",
    "H(t)=(1-\\frac{t}{T})H_B+(\\frac{t}{T})H_C\n",
    "$$\n",
    "\n",
    "注意到当$t=T$时，$H(T)=H_C$。当选取的$T$足够大时（满足绝热条件），系统将始终处于$H(t)$的瞬时基态上，此时系统的量子态将从初始哈密顿量$H_B$的基态$|\\psi (0)\\rangle$绝热地演化到目标哈密顿量$H_C$的基态$|\\psi (T)\\rangle$上，即\n",
    "\n",
    "$$\n",
    "|\\psi (T)\\rangle=\\mathcal{T}e^{-i\\int^{T}_{0} H(t)dt}|\\psi(0)\\rangle\n",
    "$$\n",
    "\n",
    "也就是说，ansatz线路需要模拟的就是$\\mathcal{T}e^{-i\\int^{T}_{0} H(t)dt}$这一演化过程。接下来我们将对这个式子进行一些近似和化简，使其变为可以在量子线路中实现的形式。\n",
    "\n",
    "考虑如下trotter公式\n",
    "\n",
    "$$\n",
    "\\mathcal{T}e^{-i\\int^T_0 H(t)dt}=\\lim_{N\\rightarrow \\infty}\\prod^N_{l=1}e^{-iH(t_l)\\Delta t},\\quad \\Delta t=\\frac{T}{N},\\quad t_l=l\\Delta t\n",
    "$$\n",
    "\n",
    "略去$O(\\Delta t^2)$项，得到\n",
    "\n",
    "$$\n",
    "\\mathcal{T}e^{-i\\int^T_0 H(t)dt}\\approx \\lim_{N\\rightarrow \\infty}\\prod^N_{l=1}e^{-iH_B(1-t_l/T)\\Delta t}e^{-iH_C t_l\\Delta t/T}\n",
    "$$\n",
    "\n",
    "令$\\beta_l=(1-t_l/T)\\Delta t$，$\\gamma_l=t_l\\Delta t/T$，并取$N$为一个有限大的整数，即得到QAOA的ansatz\n",
    "\n",
    "$$\n",
    "|\\psi(\\gamma,\\beta)\\rangle=\\prod^p_{l=1}e^{-i\\beta_l H_B}e^{-i\\gamma_l H_C}|\\psi_{in}\\rangle\n",
    "$$\n",
    "\n",
    "因此我们需要搭建的ansatz线路由$U_C(\\gamma)$和$U_B(\\beta)$这两个酉变换交替构成，其中$U_C(\\gamma)=e^{-i\\frac{\\gamma}{2} \\sum_{\\langle i,j\\rangle}Z_i Z_j}$可以由 [Rzz](https://www.mindspore.cn/mindquantum/docs/zh-CN/master/core/gates/mindquantum.core.gates.Rzz.html) 门实现，$U_B(\\beta)=e^{i\\beta \\sum_i X_i}$则相当于在每个量子比特上作用一个 [RX](https://www.mindspore.cn/mindquantum/docs/zh-CN/master/core/gates/mindquantum.core.gates.RX.html)旋转门，$\\gamma$和$\\beta$是可训练的参数。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "搭建$U_C(\\gamma)$对应的量子线路："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_hc(g, para):\n",
    "    hc = Circuit()                  # 创建量子线路\n",
    "    for i in g.edges:\n",
    "        hc += Rzz(para).on(i)        # 对图中的每条边作用Rzz门\n",
    "    hc.barrier()                    # 添加Barrier以方便展示线路\n",
    "    return hc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "线路展示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"752.8\" height=\"320.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"752.8\" height=\"320.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q4: </text><line x1=\"48.8\" x2=\"732.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"732.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"732.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"732.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"732.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"112.8\" y=\"66.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"112.8\" y=\"82.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"172.8\" y=\"20.0\" width=\"80.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"212.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"212.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><circle cx=\"172.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"252.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"172.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"252.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"280.8\" y=\"20.0\" width=\"80.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"320.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"320.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><circle cx=\"280.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"360.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"280.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"360.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"388.8\" y=\"80.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"428.8\" y=\"126.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"428.8\" y=\"142.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"488.8\" y=\"140.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"528.8\" y=\"186.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"528.8\" y=\"202.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"588.8\" y=\"200.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"628.8\" y=\"246.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"628.8\" y=\"262.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"688.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /></svg>"
      ],
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f9d290f2850>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "circuit = build_hc(graph, 'gamma')\n",
    "circuit.svg()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "搭建$U_B(\\beta)$对应的量子线路："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_hb(g, para):\n",
    "    hb = Circuit()                  # 创建量子线路\n",
    "    for i in g.nodes:\n",
    "        hb += RX(para).on(i)        # 对每个节点作用RX门\n",
    "    hb.barrier()                    # 添加Barrier以方便展示线路\n",
    "    return hb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "线路展示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"196.8\" height=\"320.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"196.8\" height=\"320.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q4: </text><line x1=\"48.8\" x2=\"176.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"176.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"176.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"176.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"176.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"72.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"72.8\" y=\"260.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"276.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"292.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"132.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /></svg>"
      ],
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f9d290f2550>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "circuit = build_hb(graph, 'beta')\n",
    "circuit.svg()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "实现了一层酉变换$U_B(\\beta) U_C(\\gamma)$的ansatz线路如下所示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"852.8\" height=\"320.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"852.8\" height=\"320.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q4: </text><line x1=\"48.8\" x2=\"832.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"832.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"832.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"832.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"832.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"112.8\" y=\"66.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"112.8\" y=\"82.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"172.8\" y=\"20.0\" width=\"80.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"212.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"212.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><circle cx=\"172.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"252.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"172.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"252.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"280.8\" y=\"20.0\" width=\"80.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"320.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"320.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><circle cx=\"280.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"360.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"280.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"360.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"388.8\" y=\"80.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"428.8\" y=\"126.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"428.8\" y=\"142.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"488.8\" y=\"140.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"528.8\" y=\"186.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"528.8\" y=\"202.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"588.8\" y=\"200.0\" width=\"80.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"628.8\" y=\"246.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"628.8\" y=\"262.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >gamma </text><rect x=\"688.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"728.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"748.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"748.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"728.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"748.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"748.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"728.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"748.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"748.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"728.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"748.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"748.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"728.8\" y=\"260.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"748.8\" y=\"276.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"748.8\" y=\"292.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >beta </text><rect x=\"788.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /></svg>"
      ],
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f9d2909f730>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "circuit = build_hc(graph, 'gamma') + build_hb(graph, 'beta')\n",
    "circuit.svg()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "为了使得最后优化的结果足够准确，我们需要将量子线路重复多次，因此我们通过如下函数搭建多层的训练网络："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_ansatz(g, p):                    # g是max-cut问题的图，p是ansatz线路的层数\n",
    "    circ = Circuit()                       # 创建量子线路\n",
    "    for i in range(p):\n",
    "        circ += build_hc(g, f'g{i}')       # 添加Uc对应的线路，参数记为g0、g1、g2...\n",
    "        circ += build_hb(g, f'b{i}')       # 添加Ub对应的线路，参数记为b0、b1、b2...\n",
    "    return circ"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "构建图对应的哈密顿量$H_C=\\sum_{(i,j)\\in C}(Z_iZ_j-1)/2$（忽略常数项和系数）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_ham(g):\n",
    "    ham = QubitOperator()\n",
    "    for i in g.edges:\n",
    "        ham += QubitOperator(f'Z{i[0]} Z{i[1]}')  # 生成HC哈密顿量\n",
    "    return ham"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 生成完整的量子线路和图所对应的哈密顿量\n",
    "\n",
    "这里我们选择`p = 4`，表示选用4层的QAOA量子线路，`ansatz`是求解该问题的量子线路，`init_state_circ`是将量子态制备到均匀叠加态（$H_B$的基态）上的量子线路。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1198.8\" height=\"672.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"1198.8\" height=\"672.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><text x=\"20.0\" y=\"280.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q4: </text><line x1=\"48.8\" x2=\"1168.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"280.0\" y2=\"280.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"40.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >H </text><rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"100.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >H </text><rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"160.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >H </text><rect x=\"72.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"220.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >H </text><rect x=\"72.8\" y=\"260.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#5e7ce0\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"280.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >H </text><rect x=\"132.8\" y=\"20.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"152.8\" y=\"66.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"152.8\" y=\"82.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><rect x=\"192.8\" y=\"20.0\" width=\"40.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"212.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"212.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><circle cx=\"192.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"232.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"192.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"232.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"260.8\" y=\"20.0\" width=\"40.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"280.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"280.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><circle cx=\"260.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"300.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"260.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"300.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"328.8\" y=\"80.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"348.8\" y=\"126.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"348.8\" y=\"142.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><rect x=\"388.8\" y=\"140.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"408.8\" y=\"186.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"408.8\" y=\"202.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><rect x=\"448.8\" y=\"200.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"468.8\" y=\"246.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"468.8\" y=\"262.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g0 </text><rect x=\"508.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"548.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"568.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"568.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b0 </text><rect x=\"548.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"568.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"568.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b0 </text><rect x=\"548.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"568.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"568.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b0 </text><rect x=\"548.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"568.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"568.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b0 </text><rect x=\"548.8\" y=\"260.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"568.8\" y=\"276.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"568.8\" y=\"292.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b0 </text><rect x=\"608.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"648.8\" y=\"20.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"668.8\" y=\"66.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"668.8\" y=\"82.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><rect x=\"708.8\" y=\"20.0\" width=\"40.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"728.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"728.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><circle cx=\"708.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"748.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"708.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"748.8\" cy=\"280.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"776.8\" y=\"20.0\" width=\"40.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"796.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"796.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><circle cx=\"776.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"816.8\" cy=\"40.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"776.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"816.8\" cy=\"160.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"844.8\" y=\"80.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"864.8\" y=\"126.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"864.8\" y=\"142.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><rect x=\"904.8\" y=\"140.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"924.8\" y=\"186.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"924.8\" y=\"202.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><rect x=\"964.8\" y=\"200.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"984.8\" y=\"246.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"984.8\" y=\"262.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g1 </text><rect x=\"1024.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"1064.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1084.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1084.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b1 </text><rect x=\"1064.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1084.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1084.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b1 </text><rect x=\"1064.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1084.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1084.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b1 </text><rect x=\"1064.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1084.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1084.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b1 </text><rect x=\"1064.8\" y=\"260.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1084.8\" y=\"276.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1084.8\" y=\"292.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b1 </text><rect x=\"1124.8\" y=\"20.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><line x1=\"58.8\" x2=\"1178.8\" y1=\"336.0\" y2=\"336.0\" stroke=\"#adb0b8\" stroke-width=\"1\" stroke-dasharray=\"5 5\" /><line x1=\"1178.8\" x2=\"1178.8\" y1=\"312.0\" y2=\"336.0\" stroke=\"#adb0b8\" stroke-width=\"1\" stroke-dasharray=\"5 5\" /><line x1=\"58.8\" x2=\"58.8\" y1=\"336.0\" y2=\"360.0\" stroke=\"#adb0b8\" stroke-width=\"1\" stroke-dasharray=\"5 5\" /><line x1=\"48.8\" x2=\"58.8\" y1=\"350.0\" y2=\"360.0\" stroke=\"#adb0b8\" stroke-width=\"2\" /><line x1=\"68.8\" x2=\"58.8\" y1=\"350.0\" y2=\"360.0\" stroke=\"#adb0b8\" stroke-width=\"2\" /><text x=\"20.0\" y=\"392.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"452.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"512.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"572.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><text x=\"20.0\" y=\"632.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q4: </text><line x1=\"48.8\" x2=\"1168.8\" y1=\"392.0\" y2=\"392.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"452.0\" y2=\"452.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"512.0\" y2=\"512.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"572.0\" y2=\"572.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"1168.8\" y1=\"632.0\" y2=\"632.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"372.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"418.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"92.8\" y=\"434.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><rect x=\"132.8\" y=\"372.0\" width=\"40.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"152.8\" y=\"508.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"152.8\" y=\"524.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><circle cx=\"132.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"172.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"132.8\" cy=\"632.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"172.8\" cy=\"632.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"200.8\" y=\"372.0\" width=\"40.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"220.8\" y=\"448.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"220.8\" y=\"464.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><circle cx=\"200.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"240.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"200.8\" cy=\"512.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"240.8\" cy=\"512.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"268.8\" y=\"432.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"288.8\" y=\"478.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"288.8\" y=\"494.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><rect x=\"328.8\" y=\"492.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"348.8\" y=\"538.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"348.8\" y=\"554.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><rect x=\"388.8\" y=\"552.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"408.8\" y=\"598.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"408.8\" y=\"614.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g2 </text><rect x=\"448.8\" y=\"372.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"488.8\" y=\"372.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"508.8\" y=\"388.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"508.8\" y=\"404.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b2 </text><rect x=\"488.8\" y=\"432.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"508.8\" y=\"448.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"508.8\" y=\"464.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b2 </text><rect x=\"488.8\" y=\"492.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"508.8\" y=\"508.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"508.8\" y=\"524.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b2 </text><rect x=\"488.8\" y=\"552.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"508.8\" y=\"568.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"508.8\" y=\"584.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b2 </text><rect x=\"488.8\" y=\"612.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"508.8\" y=\"628.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"508.8\" y=\"644.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b2 </text><rect x=\"548.8\" y=\"372.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"588.8\" y=\"372.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"608.8\" y=\"418.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"608.8\" y=\"434.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><rect x=\"648.8\" y=\"372.0\" width=\"40.0\" height=\"280\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"668.8\" y=\"508.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"668.8\" y=\"524.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><circle cx=\"648.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"688.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"648.8\" cy=\"632.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"688.8\" cy=\"632.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"716.8\" y=\"372.0\" width=\"40.0\" height=\"160\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"736.8\" y=\"448.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"736.8\" y=\"464.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><circle cx=\"716.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"756.8\" cy=\"392.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"716.8\" cy=\"512.0\" r=\"4\" fill=\"#fac209\" /><circle cx=\"756.8\" cy=\"512.0\" r=\"4\" fill=\"#fac209\" /><rect x=\"784.8\" y=\"432.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"804.8\" y=\"478.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"804.8\" y=\"494.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><rect x=\"844.8\" y=\"492.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"864.8\" y=\"538.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"864.8\" y=\"554.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><rect x=\"904.8\" y=\"552.0\" width=\"40.0\" height=\"100\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"924.8\" y=\"598.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >Rzz </text><text x=\"924.8\" y=\"614.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >g3 </text><rect x=\"964.8\" y=\"372.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /><rect x=\"1004.8\" y=\"372.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1024.8\" y=\"388.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1024.8\" y=\"404.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b3 </text><rect x=\"1004.8\" y=\"432.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1024.8\" y=\"448.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1024.8\" y=\"464.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b3 </text><rect x=\"1004.8\" y=\"492.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1024.8\" y=\"508.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1024.8\" y=\"524.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b3 </text><rect x=\"1004.8\" y=\"552.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1024.8\" y=\"568.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1024.8\" y=\"584.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b3 </text><rect x=\"1004.8\" y=\"612.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"1024.8\" y=\"628.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"1024.8\" y=\"644.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b3 </text><rect x=\"1064.8\" y=\"372.0\" width=\"20\" height=\"280\" fill=\"gray\" fill-opacity=\"0.8\" /></svg>"
      ],
      "text/plain": [
       "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f9d29045f70>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "p = 4\n",
    "ham = Hamiltonian(build_ham(graph))              # 生成哈密顿量\n",
    "init_state_circ = UN(H, graph.nodes)             # 生成均匀叠加态，即对所有量子比特作用H门\n",
    "ansatz = build_ansatz(graph, p)                  # 生成ansatz线路\n",
    "circ = init_state_circ + ansatz                  # 将初始化线路与ansatz线路组合成一个线路\n",
    "circ.svg(width=1200)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 方法一：利用传统优化算法完成优化搜索\n",
    "\n",
    "### 生成梯度算子\n",
    "\n",
    "首先，我们利用模拟器生成计算QAOA变分量子线路期望值和梯度的运算算子。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "sim = Simulator('mqvector', circ.n_qubits)\n",
    "grad_ops = sim.get_expectation_with_grad(ham, circ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`grad_ops`是一个可以用来计算期望值和期望值关于变分参数的导数的算子，例如我们可以通过如下方式计算线路在参数为 `p0` 时的期望值和导数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expectation Value:  [[2.2839928+4.88195544e-17j]]\n",
      "Expectation Value Shape:  (1, 1)\n",
      "Gradient:  [[[ 0.60966156+0.j -0.50977303+0.j  1.96920626+0.j -1.89443604+0.j\n",
      "    0.9840882 +0.j -1.85238736+0.j  1.27387126+0.j -0.03135037+0.j]]]\n",
      "Gradient Shape:  (1, 1, 8)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "rng = np.random.default_rng(10)\n",
    "p0 = rng.random(size=len(circ.params_name)) * np.pi * 2 - np.pi\n",
    "f, g = grad_ops(p0)\n",
    "print('Expectation Value: ', f)\n",
    "print('Expectation Value Shape: ', f.shape)\n",
    "print('Gradient: ', g)\n",
    "print('Gradient Shape: ', g.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里，我们算出来期望值是一个$(m=1, n=1)$维的数组，其中 $m$ 表示本次运算将多少数据通过编码器编码成了量子态，由于QAOA任务不用编码器，因此$m$取默认值1，$n$ 表示本次运算计算了多少个哈密顿量期望值（MindQuantum支持多哈密顿量并行处理），此处我们只计算了`ham`的期望值，所以$n=1$。同理，对于梯度值来说，它的维度是$(m=1,n=1,k=8)$，新增的维度$k=8$表示整个线路中的ansatz变分参数个数。\n",
    "\n",
    "我们引入`scipy`中的二阶优化器`BFGS`来对Max-Cut问题进行优化，为此首先定义待优化函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2.2839927952206174,\n",
       " array([ 0.60966156, -0.50977303,  1.96920626, -1.89443604,  0.9840882 ,\n",
       "        -1.85238736,  1.27387126, -0.03135037]))"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0604\n",
    "global step\n",
    "step = 0\n",
    "\n",
    "def fun(p, grad_ops):\n",
    "    global step\n",
    "    f, g = grad_ops(p)\n",
    "    f = np.real(f)[0, 0]\n",
    "    g = np.real(g)[0, 0]\n",
    "    step += 1\n",
    "    if step % 10 == 0:\n",
    "        print(f\"train step: {step} , cut: [{(len(graph.edges) - f) / 2}]\")\n",
    "    return f, g\n",
    "\n",
    "fun(p0, grad_ops)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 训练过程\n",
    "\n",
    "`BFGS`是一个二阶优化器，效果较好。指定`jac=True`，表示告诉优化器，待优化的函数在返回函数值的同时也会返回梯度值。如设定为`False`，优化器会利用差分法自行计算近似梯度，这会消耗大量算力。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train step: 10 , cut: [3.5103176644442238]\n",
      "train step: 20 , cut: [3.868695972469235]\n",
      "train step: 30 , cut: [4.194720830469368]\n",
      "train step: 40 , cut: [4.649109856438022]\n",
      "train step: 50 , cut: [4.752059940467564]\n",
      "train step: 60 , cut: [4.777656304269479]\n",
      "train step: 70 , cut: [4.820166856240324]\n",
      "train step: 80 , cut: [4.825019042509073]\n",
      "train step: 90 , cut: [4.826176814772741]\n"
     ]
    }
   ],
   "source": [
    "from scipy.optimize import minimize\n",
    "\n",
    "step = 0\n",
    "res = minimize(fun, p0, args=(grad_ops, ), method='bfgs', jac=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在最优解时，训练得到的变分参数为："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'g0': -0.7937405245633787, 'b0': 0.24377670109607055, 'g1': 1.6118673525265843, 'b1': -2.0908435247717794, 'g2': -0.21919996577600231, 'b2': -1.955308095101507, 'g3': 1.2663769844140762, 'b3': 2.752892656008665}\n"
     ]
    }
   ],
   "source": [
    "print(dict(zip(circ.params_name, res.x)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 方法二：利用 MindSpore 机器学习框架完成量子神经网络训练\n",
    "\n",
    "### 搭建待训练量子神经网络\n",
    "\n",
    "由于该问题不需要编码层量子线路，我们这里使用[MQAnsatzOnlyLayer](https://www.mindspore.cn/mindquantum/docs/zh-CN/master/framework/layer/mindquantum.framework.MQAnsatzOnlyLayer.html)作为待训练的量子神经网络，并采用[Adam](https://www.mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Adam.html#mindspore.nn.Adam)优化器。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import mindspore as ms\n",
    "ms.set_context(mode=ms.PYNATIVE_MODE, device_target=\"CPU\")\n",
    "\n",
    "sim = Simulator('mqvector', circ.n_qubits)                     # 创建模拟器，backend使用‘mqvector’，能模拟5个比特（'circ'线路中包含的比特数）\n",
    "grad_ops = sim.get_expectation_with_grad(ham, circ)            # 获取计算变分量子线路的期望值和梯度的算子\n",
    "net = MQAnsatzOnlyLayer(grad_ops)                              # 生成待训练的神经网络\n",
    "opti = nn.Adam(net.trainable_params(), learning_rate=0.05)     # 设置针对网络中所有可训练参数、学习率为0.05的Adam优化器\n",
    "train_net = nn.TrainOneStepCell(net, opti)                     # 对神经网络进行一步训练"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 训练并展示结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train step: 0 , cut: [2.9993052]\n",
      "train step: 10 , cut: [4.1751137]\n",
      "train step: 20 , cut: [4.6125264]\n",
      "train step: 30 , cut: [4.7552934]\n",
      "train step: 40 , cut: [4.826446]\n",
      "train step: 50 , cut: [4.8666077]\n",
      "train step: 60 , cut: [4.881803]\n",
      "train step: 70 , cut: [4.907435]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train step: 80 , cut: [4.928264]\n",
      "train step: 90 , cut: [4.9379854]\n",
      "train step: 100 , cut: [4.9379473]\n",
      "train step: 110 , cut: [4.938938]\n",
      "train step: 120 , cut: [4.93915]\n",
      "train step: 130 , cut: [4.9391956]\n",
      "train step: 140 , cut: [4.939249]\n",
      "train step: 150 , cut: [4.9392486]\n",
      "train step: 160 , cut: [4.939256]\n",
      "train step: 170 , cut: [4.9392567]\n",
      "train step: 180 , cut: [4.939257]\n",
      "train step: 190 , cut: [4.939257]\n"
     ]
    }
   ],
   "source": [
    "for i in range(200):\n",
    "    cut = (len(graph.edges) - train_net()) / 2      # 将神经网络训练一步并计算得到的结果（切割边数）。注意：每当'train_net()'运行一次，神经网络就训练了一步\n",
    "    if i % 10 == 0:\n",
    "        print(\"train step:\", i, \", cut:\", cut)  # 每训练10步，打印当前训练步数和当前得到的切割边数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据上面的训练结果我们发现，该问题哈密顿量的基态能量对应的边切割数趋近于5。\n",
    "\n",
    "### 最优参数\n",
    "\n",
    "前面我们通过训练得到了量子线路中参数的最优值，下面，我们将最优参数提取出来并存储为字典类型，与之前线路中命名的参数一一对应。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'g0': 0.44899243, 'b0': -1.1390328, 'g1': 0.9063166, 'b1': -0.9446803, 'g2': 1.0676377, 'b2': -0.677542, 'g3': 1.16797, 'b3': -0.38235208}\n"
     ]
    }
   ],
   "source": [
    "pr = dict(zip(ansatz.params_name, net.weight.asnumpy())) # 获取线路参数\n",
    "print(pr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 概率图\n",
    "\n",
    "我们将最优参数代入量子线路，通过对量子线路进行1000次采样，画出最终量子态在计算基矢下的概率分布："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"430.0\" height=\"597.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"430.0\" height=\"597.0\" fill=\"#ffffff\" /><text x=\"10\" y=\"17.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >Shots:\n",
       " 1000 </text><text x=\"10\" y=\"31.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" >Keys: q4 q3 q2 q1 q0 </text><line x1=\"60.0\" x2=\"420.0\" y1=\"62.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"60.0\" x2=\"60.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"62.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.0 </text><line x1=\"60.0\" x2=\"60.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"120.0\" x2=\"120.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"122.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.05 </text><line x1=\"120.0\" x2=\"120.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" /><line x1=\"180.0\" x2=\"180.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"182.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.1 </text><line x1=\"180.0\" x2=\"180.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" /><line x1=\"240.0\" x2=\"240.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"242.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.151 </text><line x1=\"240.0\" x2=\"240.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" /><line x1=\"300.0\" x2=\"300.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"302.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.201 </text><line x1=\"300.0\" x2=\"300.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" /><line x1=\"360.0\" x2=\"360.0\" y1=\"55.0\" y2=\"62.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><text x=\"362.0\" y=\"60.0\" font-size=\"12px\" dominant-baseline=\"bottom\" text-anchor=\"start\" fill=\"#575d6c\" >0.251 </text><line x1=\"360.0\" x2=\"360.0\" y1=\"62.0\" y2=\"587.0\" stroke=\"#dfe1e6\" stroke-width=\"1\" /><text x=\"51.0\" y=\"85.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >00000 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"85.0\" y2=\"85.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"73.0\" width=\"1.1952191235059761\" height=\"24\" id=\"bar_0_1698667904158684313\" fill=\"#5e7ce0\" /><text x=\"71.19521912350598\" y=\"85.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_0_1698667904158703553\" fill-opacity=\"0\" >1 </text><text x=\"51.0\" y=\"115.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >00001 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"115.0\" y2=\"115.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"103.0\" width=\"2.3904382470119523\" height=\"24\" id=\"bar_1_1698667904158720821\" fill=\"#16acff\" /><text x=\"72.39043824701196\" y=\"115.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_1_1698667904158731590\" fill-opacity=\"0\" >2 </text><text x=\"51.0\" y=\"145.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >00100 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"145.0\" y2=\"145.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"133.0\" width=\"1.1952191235059761\" height=\"24\" id=\"bar_2_1698667904158746208\" fill=\"#5e7ce0\" /><text x=\"71.19521912350598\" y=\"145.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_2_1698667904158754857\" fill-opacity=\"0\" >1 </text><text x=\"51.0\" y=\"175.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >00101 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"175.0\" y2=\"175.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"163.0\" width=\"11.952191235059761\" height=\"24\" id=\"bar_3_1698667904158788130\" fill=\"#16acff\" /><text x=\"81.95219123505976\" y=\"175.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_3_1698667904158797327\" fill-opacity=\"0\" >10 </text><text x=\"51.0\" y=\"205.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >01001 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"205.0\" y2=\"205.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"193.0\" width=\"292.82868525896413\" height=\"24\" id=\"bar_4_1698667904158811857\" fill=\"#5e7ce0\" /><text x=\"362.82868525896413\" y=\"205.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_4_1698667904158820840\" fill-opacity=\"0\" >245 </text><text x=\"51.0\" y=\"235.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >01010 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"235.0\" y2=\"235.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"223.0\" width=\"3.585657370517928\" height=\"24\" id=\"bar_5_1698667904158834378\" fill=\"#16acff\" /><text x=\"73.58565737051794\" y=\"235.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_5_1698667904158843049\" fill-opacity=\"0\" >3 </text><text x=\"51.0\" y=\"265.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >01011 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"265.0\" y2=\"265.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"253.0\" width=\"292.82868525896413\" height=\"24\" id=\"bar_6_1698667904158856134\" fill=\"#5e7ce0\" /><text x=\"362.82868525896413\" y=\"265.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_6_1698667904158871320\" fill-opacity=\"0\" >245 </text><text x=\"51.0\" y=\"295.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >01101 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"295.0\" y2=\"295.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"283.0\" width=\"1.1952191235059761\" height=\"24\" id=\"bar_7_1698667904158884863\" fill=\"#16acff\" /><text x=\"71.19521912350598\" y=\"295.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_7_1698667904158893336\" fill-opacity=\"0\" >1 </text><text x=\"51.0\" y=\"325.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >10001 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"325.0\" y2=\"325.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"313.0\" width=\"1.1952191235059761\" height=\"24\" id=\"bar_8_1698667904158909269\" fill=\"#5e7ce0\" /><text x=\"71.19521912350598\" y=\"325.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_8_1698667904158918235\" fill-opacity=\"0\" >1 </text><text x=\"51.0\" y=\"355.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >10010 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"355.0\" y2=\"355.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"343.0\" width=\"2.3904382470119523\" height=\"24\" id=\"bar_9_1698667904158933311\" fill=\"#16acff\" /><text x=\"72.39043824701196\" y=\"355.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_9_1698667904158942681\" fill-opacity=\"0\" >2 </text><text x=\"51.0\" y=\"385.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >10100 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"385.0\" y2=\"385.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"373.0\" width=\"260.5577689243028\" height=\"24\" id=\"bar_10_1698667904158955824\" fill=\"#5e7ce0\" /><text x=\"330.5577689243028\" y=\"385.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_10_1698667904158964609\" fill-opacity=\"0\" >218 </text><text x=\"51.0\" y=\"415.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >10101 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"415.0\" y2=\"415.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"403.0\" width=\"2.3904382470119523\" height=\"24\" id=\"bar_11_1698667904158979403\" fill=\"#16acff\" /><text x=\"72.39043824701196\" y=\"415.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_11_1698667904158989544\" fill-opacity=\"0\" >2 </text><text x=\"51.0\" y=\"445.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >10110 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"445.0\" y2=\"445.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"433.0\" width=\"300.0\" height=\"24\" id=\"bar_12_1698667904159004670\" fill=\"#5e7ce0\" /><text x=\"370.0\" y=\"445.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_12_1698667904159018162\" fill-opacity=\"0\" >251 </text><text x=\"51.0\" y=\"475.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >11010 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"475.0\" y2=\"475.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"463.0\" width=\"15.537848605577688\" height=\"24\" id=\"bar_13_1698667904159031611\" fill=\"#16acff\" /><text x=\"85.5378486055777\" y=\"475.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_13_1698667904159042677\" fill-opacity=\"0\" >13 </text><text x=\"51.0\" y=\"505.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >11101 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"505.0\" y2=\"505.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"493.0\" width=\"2.3904382470119523\" height=\"24\" id=\"bar_14_1698667904159058206\" fill=\"#5e7ce0\" /><text x=\"72.39043824701196\" y=\"505.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_14_1698667904159071411\" fill-opacity=\"0\" >2 </text><text x=\"51.0\" y=\"535.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >11110 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"535.0\" y2=\"535.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"523.0\" width=\"1.1952191235059761\" height=\"24\" id=\"bar_15_1698667904159084703\" fill=\"#16acff\" /><text x=\"71.19521912350598\" y=\"535.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_15_1698667904159093670\" fill-opacity=\"0\" >1 </text><text x=\"51.0\" y=\"565.0\" font-size=\"12px\" dominant-baseline=\"middle\" text-anchor=\"end\" fill=\"#575d6c\" >11111 </text><line x1=\"53.0\" x2=\"60.0\" y1=\"565.0\" y2=\"565.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"60.0\" y=\"553.0\" width=\"2.3904382470119523\" height=\"24\" id=\"bar_16_1698667904159108706\" fill=\"#5e7ce0\" /><text x=\"72.39043824701196\" y=\"565.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"start\" fill=\"#575d6c\" id=\"bar_text_16_1698667904159117581\" fill-opacity=\"0\" >2 </text><animate xlink:href=\"#bar_0_1698667904158684313\" attributeName=\"width\" from=\"0\" to=\"1.1952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 1.1952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_1_1698667904158720821\" attributeName=\"width\" from=\"0\" to=\"2.3904382470119523\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 2.3904382470119523\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_2_1698667904158746208\" attributeName=\"width\" from=\"0\" to=\"1.1952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 1.1952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_3_1698667904158788130\" attributeName=\"width\" from=\"0\" to=\"11.952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 11.952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_4_1698667904158811857\" attributeName=\"width\" from=\"0\" to=\"292.82868525896413\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 292.82868525896413\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_5_1698667904158834378\" attributeName=\"width\" from=\"0\" to=\"3.585657370517928\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 3.585657370517928\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_6_1698667904158856134\" attributeName=\"width\" from=\"0\" to=\"292.82868525896413\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 292.82868525896413\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_7_1698667904158884863\" attributeName=\"width\" from=\"0\" to=\"1.1952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 1.1952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_8_1698667904158909269\" attributeName=\"width\" from=\"0\" to=\"1.1952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 1.1952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_9_1698667904158933311\" attributeName=\"width\" from=\"0\" to=\"2.3904382470119523\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 2.3904382470119523\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_10_1698667904158955824\" attributeName=\"width\" from=\"0\" to=\"260.5577689243028\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 260.5577689243028\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_11_1698667904158979403\" attributeName=\"width\" from=\"0\" to=\"2.3904382470119523\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 2.3904382470119523\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_12_1698667904159004670\" attributeName=\"width\" from=\"0\" to=\"300.0\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 300.0\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_13_1698667904159031611\" attributeName=\"width\" from=\"0\" to=\"15.537848605577688\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 15.537848605577688\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_14_1698667904159058206\" attributeName=\"width\" from=\"0\" to=\"2.3904382470119523\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 2.3904382470119523\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_15_1698667904159084703\" attributeName=\"width\" from=\"0\" to=\"1.1952191235059761\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 1.1952191235059761\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_16_1698667904159108706\" attributeName=\"width\" from=\"0\" to=\"2.3904382470119523\" dur=\"0.3s\" calcMode=\"spline\" values=\"0; 2.3904382470119523\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" /><animate xlink:href=\"#bar_12_1698667904159004670\" attributeName=\"fill\" from=\"#5e7ce0\" to=\"#fac209\" dur=\"0.15s\" calcMode=\"spline\" values=\"#5e7ce0; #fac209\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_0_1698667904158703553\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_1_1698667904158731590\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_2_1698667904158754857\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_3_1698667904158797327\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_4_1698667904158820840\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_5_1698667904158843049\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_6_1698667904158871320\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_7_1698667904158893336\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_8_1698667904158918235\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_9_1698667904158942681\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_10_1698667904158964609\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_11_1698667904158989544\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_12_1698667904159018162\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_13_1698667904159042677\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_14_1698667904159071411\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_15_1698667904159093670\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><animate xlink:href=\"#bar_text_16_1698667904159117581\" attributeName=\"fill-opacity\" from=\"0\" to=\"1\" dur=\"0.15s\" calcMode=\"spline\" values=\"0; 1\" keyTimes=\"0; 1\" keySplines=\"0.42 0 1 0.8;\" fill=\"freeze\" begin=\"0.3s\" /><text x=\"217.5\" y=\"41.0\" font-size=\"14px\" dominant-baseline=\"middle\" text-anchor=\"middle\" >probability </text></svg>"
      ],
      "text/plain": [
       "<mindquantum.io.display.measure_res_svg_drawer.SVGMeasure at 0x7f9ce5fc9f70>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pylint: disable=W0104\n",
    "circ.measure_all()                               # 为线路中所有比特添加测量门\n",
    "sim.sampling(circ, pr=pr, shots=1000).svg()      # 运行线路1000次并打印结果"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据概率分布图我们发现，该Max-Cut问题具有四个简并解，每个解对应的概率大概为25%。\n",
    "\n",
    "- `01001`：编号为1、2、4的顶点在左边，编号为0、3的顶点在右边。\n",
    "- `10110`：编号为0、3的顶点在左边，编号为1、2、4的顶点在右边。\n",
    "- `01011`：编号为2、4的顶点在左边，编号为0、1、3的顶点在右边。\n",
    "- `10100`：编号为0、1、3的顶点在左边，编号为2、4的顶点在右边。\n",
    "\n",
    "可以发现，以上结果与先前通过穷举法得到的结果相符。\n",
    "\n",
    "## 总结\n",
    "\n",
    "这里我们通过量子近似优化算法来解决了Max-Cut问题，并得到了案例中的图对应的最大切割方案。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<table border=\"1\">\n",
       "  <tr>\n",
       "    <th>Software</th>\n",
       "    <th>Version</th>\n",
       "  </tr>\n",
       "<tr><td>mindquantum</td><td>0.9.11</td></tr>\n",
       "<tr><td>scipy</td><td>1.10.1</td></tr>\n",
       "<tr><td>numpy</td><td>1.21.6</td></tr>\n",
       "<tr>\n",
       "    <th>System</th>\n",
       "    <th>Info</th>\n",
       "</tr>\n",
       "<tr><td>Python</td><td>3.9.13</td></tr><tr><td>OS</td><td>Linux x86_64</td></tr><tr><td>Memory</td><td>16.62 GB</td></tr><tr><td>CPU Max Thread</td><td>16</td></tr><tr><td>Date</td><td>Mon Oct 30 20:11:44 2023</td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<mindquantum.utils.show_info.InfoTable at 0x7f9ce5fdac40>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from mindquantum.utils.show_info import InfoTable\n",
    "\n",
    "InfoTable('mindquantum', 'scipy', 'numpy')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 参考文献\n",
    "\n",
    "[1] Edward Farhi, Jeffrey Goldstone, and Sam Gutmann. [A Quantum Approximate Optimization Algorithm](https://arxiv.org/pdf/1411.4028.pdf)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MindSpore",
   "language": "python",
   "name": "mindspore"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
